package com.guoguo.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.guoguo.dao.ShortUrlMongoDao;
import com.guoguo.entity.ShortUrl;
import com.guoguo.service.IShortUrlMongoService;
import com.guoguo.utils.StringUtils;

/**
 * Created by WYZ on 2017/10/30.
 */
@Service
public class ShortUrlMongoService implements IShortUrlMongoService {
	@Autowired
    private ShortUrlMongoDao shortUrlMongoDao;
	/**  
	 * @Description： 获取原始长的URL
	 * @author: WYZ 
	 * @throws Exception 
	 * @since: 2017年10月30日 下午4:12:54  
	 */
	@Override
	public String getOldUrl(String newUrl) throws Exception {
		ShortUrl shortUrl = shortUrlMongoDao.getById(newUrl);
		if(shortUrl != null && !StringUtils.isEmpty(shortUrl.getNewUrl())){
			return shortUrl.getOldUrl();
		}else{
			return null;
		}
	}
    
}
